package lhb.test.SC.dam.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import lhb.test.SC.common.util.PrintUtil;
import lhb.test.SC.uum.feign.UserClient;

@RestController
@RequestMapping("asset")
public class AssetController {
	
	@Autowired
	RestTemplate restTemplate;
	
	@Autowired
	UserClient userClient;
	
	/**
	 *获取平均下载次数 
	 */
	@RequestMapping("getAvgAssetCount")
	public Object getAvgDownloadCount(HttpServletRequest request){
		PrintUtil.printRequestHeader(request);
		PrintUtil.printSession(request);
		int downloadCount = 1000;
//		
//		HttpHeaders headers = new HttpHeaders();
//		headers.add("cookie", request.getHeader("cookie"));
//		int userCount = (Integer) restTemplate.postForObject("http://uum/user/getUserCount",
//				new HttpEntity<String>(headers), Integer.class);
		
//		int userCount = (Integer)restTemplate.getForObject("http://uum/user/getUserCount",Integer.class);
		
		int userCount = userClient.getUserCount(request.getHeader("cookie"));
		
		return downloadCount/userCount;
	}
}
